<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    function cibcurRequest(urls, maxLength) {
      return new Promise((resolve, reject) => {
        if (urls.length === 0) {
          resolve([]);
          return;
        }

        const results = [];
        let index = 0;

        async function request() {
          if (index === urls.length) {
            return;
          }

          const i = index;
          const url = urls[i];
          index++;
          console.log(`Requesting: ${url}`, index);
          try {
            const resp = await fetch(url);
            results[i] = resp;
          } catch (error) {
            results[i] = error;
          } finally {
            if (index === urls.length) {
              resolve(results);
            } else {
              request();
            }
          }
        }

        let requestCount = Math.min(maxLength, urls.length);
        for (let i = 0; i < requestCount; i++) {
          request();
        }
      });
    }
  </script>
  <script>
    const urls = [];
    for (let i = 1; i <= 20; i++) {
      urls.push(`https://example.com/page${i}.html`);
    }
    cibcurRequest(urls, 3).then(responses => {
      console.log(responses)
    })
  </script>
</body>
</html>